<script lang="ts">
import {Vue, Component, Prop, Watch, Emit, Inject} from 'vue-property-decorator';
import {CommonResult} from "../../../plugins/dto";
import {ClassifyTreeDto} from "../CommodityClassify/type";
import masterModal from "../../../../../api/module/masterModal";
import {ClassData} from "../../../type";


@Component({
  name: "CommodityClass",
})
export default class CommodityClass extends Vue {
  @Prop({default:{}}) item!:ClassData;
  public itemStr:string="";
  async mounted(){
    const res:CommonResult<ClassifyTreeDto[]> = await masterModal.getClassifyData()
    const strList:string[] = []
    if(res.code == 200){
      res.data.forEach(i=>{
        if(`T${i.code}` === this.item.classFirst){
          strList.push(i.name)
          if(i.children.length){
            i.children.forEach(j=>{
              if(j.code === this.item.classSecond){
                strList.push(j.name)
                if(j.children.length){
                  j.children.forEach(k=>{
                    if(k.code === this.item.classThird){
                      strList.push(k.name)
                      if(k.children.length){
                        k.children.forEach(m=>{
                          if(m.code === this.item.classFourth){
                            strList.push(m.name)
                          }
                        })
                      }
                    }
                  })
                }
              }
            })
          }
        }
      })
    }
    this.itemStr = strList.join(">>")
  }
}
</script>

<template>
  <div>
    {{itemStr}}
  </div>
</template>

<style scoped lang="scss">

</style>